Repository navigation
fix(manager): make DRAGONFLY_PAT seeding idempotent on restart - #5152
Open
harshitnub077 wants to merge 1 commit into
Open
harshitnub077 wants to merge 1 commit into
harshitnub077 wants to merge 1 commit into
Conversation
The manager seeds a personal access token from DRAGONFLY_PAT on every start with a plain INSERT. Every start after the first breaks the unique index on the token name or value, seed returns the error and the manager exits, so it crash-loops after its first restart: Error 1062 (23000): Duplicate entry 'default' for key 'personal_access_token.uk_personal_access_token_name' Create the token with ON CONFLICT DO NOTHING (ON DUPLICATE KEY UPDATE id=id on MySQL). A scoped lookup is not enough: the unique indexes also cover soft-deleted rows, which GORM's default scope hides, and the database also settles races between replicas that start at once. An existing token is left unchanged. It is not reactivated or extended, so a restart never undoes a revocation. If the "default" token holds a different value, log a warning instead of failing. Signed-off-by: Harshit Kudhial <harshitkudhial@gmail.com>
harshitnub077
requested review from
ClementMaH,
EvanCley,
Fricounet,
bergwolf,
hhhhsdxxxx and
mingcheng
November 27, 2026 05:20
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5152 +/- ##
==========================================
+ Coverage 63.08% 63.40% +0.31%
==========================================
Files 232 232
Lines 23171 23184 +13
==========================================
+ Hits 14618 14699 +81
+ Misses 7902 7817 -85
- Partials 651 668 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Author
|
Hi maintainers, the only failing check is Classify PR, which needs exactly one label. This is a bug fix (the manager crash-loops on restart when |
harshitnub077
force-pushed
the
fix/manager-pat-seed-idempotent
branch
from
November 28, 2026 16:27
86c8f4b to
d8289f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
DRAGONFLY_PATis set, the manager seeds a personal access token nameddefaulton every start with a plainINSERT. The first start works. Every later start breaks a unique index (uk_personal_access_token_nameoruk_personal_access_token),seedreturns the error, and the manager exits:In Kubernetes this turns into a crash loop after the first manager restart. Seen with helm chart 1.11.0 (app 2.5.4), MySQL, and
manager.extraEnvVars: [{name: DRAGONFLY_PAT, value: ...}].This PR moves the seeding into
seedPersonalAccessTokenand creates the token withclause.OnConflict{DoNothing: true}:INSERT ... ON DUPLICATE KEY UPDATE id=idINSERT ... ON CONFLICT DO NOTHINGWhy a conflict clause and not
First/FirstOrCreate:is_delflag), but GORM's default scope hides them. If an admin deletes the seeded token through the API, a scoped lookup finds nothing, the insert collides with the deleted row, and the manager crash-loops again.If a token with that value or name already exists, it is left unchanged. The manager does not reactivate or extend an inactive, expired or deleted token. A token in that state was most likely revoked on purpose, and a pod restart should not undo that. If the existing
defaulttoken has a different value (for example afterDRAGONFLY_PATwas changed), the manager starts normally and logs a warning thatDRAGONFLY_PATis not used, instead of crashing. Changing the token through the env var would be a separate feature.Related Issue
Fixes #5151
Motivation and Context
With
DRAGONFLY_PATset, the manager could only be started once against the same database. Any restart (rolling update, node drain, OOM) left it in a crash loop.Types of changes
Checklist
Testing
TestSeed_PersonalAccessToken(sqlite, same setup asmanager/gc) runsmigrateand thenseedtwice for: a fresh database, an existing inactive/expired token with the same value, a soft-deleted token with the same value, and an existingdefaulttoken with a different value. All four cases fail onmainwithUNIQUE constraint failedand pass with this change.newMysql(migrate + seed) several times. Onmainthe second start fails with the 1062 error above. With this change, three starts succeed and leave exactly one token, and a changedDRAGONFLY_PATlogs the warning.go build ./...,go test ./manager/...,golangci-lint run ./manager/database/...(0 issues).